import React, { Component } from 'react'
import { Text, StyleSheet, View, Button } from 'react-native'
import Storage from './storage';

export default class index extends Component {

     storeData = async (value) => {
        await Storage.set('my-key', value);
      };

      getData = async () => {
        const value = await Storage.get('my-key');
        if (value && value !== null) {
          alert(value)
        }
      };

      setData = () =>{
        this.storeData('Hello World')
        alert('数据存储成功')
      }

  render() {
    return (
      <View style={[styles.container]}>
        <Button style={[styles.button]} title='存储' onPress={this.setData}/>
        <Button style={[styles.button]} title='读取' onPress={this.getData}/>
        <Button style={[styles.button]} title='清除' onPress={Storage.clear}/>
      </View>
    )
  }
}

const styles = StyleSheet.create({
    container:{
        flex: 1,
        justifyContent:'space-around',
        marginLeft: 10,
        marginRight: 10,
    },
    button:{
        fontSize: 34,
    }
})
